/*
 * @Author: 薛严 348352046@qq.com
 * @Date: 2022-11-12 19:01:35
 * @LastEditors: 薛严 348352046@qq.com
 * @LastEditTime: 2022-11-12 19:57:14
 * @FilePath: /gov-baoan-h5/src/utils/storageUtils.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/**
 * 简单封装本地存储
 */

type storageType = {
  key: string
  value?: any
}

const STORAGE = window.localStorage

// 存放获取的key
export const storageKey = {
  REGISTRATIONFORM: 'RegistrationForm', // 登记表单信息
}

// 设置存储
export const setStorage = ({ key, value }: storageType) => {
  const data = JSON.stringify(value)
  STORAGE.setItem(key, data)
}

// 获取存储
export const getStorage = ({ key }: storageType) => {
  return STORAGE.getItem(key) ? JSON.parse(STORAGE.getItem(key) ?? '') : null
}

// 清除存储
export const clear = ({ key }: storageType) => {
  STORAGE.removeItem(key)
}

// 清除所有存储
export const clearAll = () => {
  STORAGE.clear()
}
